var fs = require("fs")
var options ={
  secure :true,
  key: fs.readFileSync('./ssl.key'),
  cert: fs.readFileSync('./ssl.csr'),
}

var WebSocketServer = require('nodejs-websocket');
  let server = WebSocketServer.createServer(options,connection => {
    connection.on('text', function(result) {
      console.log('发送消息', result);
      // chrome 中服务器发送部分在websoket 协议中显示为红色部分
      connection.send("客户端信息已经收到, 结果是"+ result )
    })
    connection.on('connect', function(code) {
      console.log('开启连接', code)
    })
    connection.on('close', function(code) {
      console.log('关闭连接', code)
    })
    connection.on('error', function(code) {
      console.log('异常关闭', code)
    })
  }).listen(3000,()=>{console.log("服务启动成功")});
